/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package be;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author yzavaleta
 */
@Entity
@Table(name = "componente")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Componente.findAll", query = "SELECT c FROM Componente c"),
    @NamedQuery(name = "Componente.findById", query = "SELECT c FROM Componente c WHERE c.componentePK.id = :id"),
    @NamedQuery(name = "Componente.findByCodigo", query = "SELECT c FROM Componente c WHERE c.codigo = :codigo"),
    @NamedQuery(name = "Componente.findByDescripcion", query = "SELECT c FROM Componente c WHERE c.descripcion = :descripcion"),
    @NamedQuery(name = "Componente.findByProductoId", query = "SELECT c FROM Componente c WHERE c.componentePK.productoId = :productoId")})
public class Componente implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ComponentePK componentePK;
    @Size(max = 20)
    @Column(name = "codigo")
    private String codigo;
    @Size(max = 40)
    @Column(name = "descripcion")
    private String descripcion;
    @JoinColumn(name = "producto_id", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Producto producto;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "componente", fetch = FetchType.LAZY)
    private List<Presupuestodetalle> presupuestodetalleList;

    public Componente() {
    }

    public Componente(ComponentePK componentePK) {
        this.componentePK = componentePK;
    }

    public Componente(int id, int productoId) {
        this.componentePK = new ComponentePK(id, productoId);
    }

    public ComponentePK getComponentePK() {
        return componentePK;
    }

    public void setComponentePK(ComponentePK componentePK) {
        this.componentePK = componentePK;
    }

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public Producto getProducto() {
        return producto;
    }

    public void setProducto(Producto producto) {
        this.producto = producto;
    }

    @XmlTransient
    public List<Presupuestodetalle> getPresupuestodetalleList() {
        return presupuestodetalleList;
    }

    public void setPresupuestodetalleList(List<Presupuestodetalle> presupuestodetalleList) {
        this.presupuestodetalleList = presupuestodetalleList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (componentePK != null ? componentePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Componente)) {
            return false;
        }
        Componente other = (Componente) object;
        if ((this.componentePK == null && other.componentePK != null) || (this.componentePK != null && !this.componentePK.equals(other.componentePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "be.Componente[ componentePK=" + componentePK + " ]";
    }
    
}
